export default {
    namespaced: true,
    state: {
        token:''
    },
    getters: {
        
    },
    mutations: {
        setToken(state,payload){
            state.token=payload.token
        }
    },
    actions: { 
     async fetchToken({commit}){
        //获取用户信息
      const [err,{ encryptedData, rawData, iv, signature }]=await uni.getUserProfile({
        desc:"用于支付"
      })
      
      //获取code临时凭证
      const [err2,{code}]=await uni.login()
      
      //获取用户toke
      const {token} = await uni.$u.post('/users/wxlogin',{
        encryptedData, 
        rawData, 
        iv, 
        signature,
        code
      })

      commit("setToken",{token})
     }
    }
}